<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/content/variable.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/content/head.jsp"%>
</head>
<body>
    <div class="row">
        <div class="col-md-12">
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">修改小说内容</h3>
                </div>
                <form id="editInfo" class="form-horizontal" role="form" onsubmit="javascript:saveInfo();">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="novelCover" class="col-sm-2 control-label">小说封面：</label>
                             <div class="col-md-8">
								<input type="file" class="file-loading" id="novelCoverFile" accept="img/*">
								<input type="text" class="form-control input-sm" id="novelCoverUrl" name="novelCover" value="${obj.novelCover}"> 
							</div>
							<div class="col-sm-2">
								<span class="help-inline" style="color: #a94442"></span>
							</div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="novelContent" class="col-sm-2 control-label">小说内容：</label>
                             <div class="col-md-8">
								<input type="file" class="file-loading" id="novelContentFile" accept="txt/*">
								<input type="text" class="form-control input-sm" id="novelContentUrl" name="novelContent" value="${obj.novelContent}"> 
							</div>
							<div class="col-sm-2">
								<span class="help-inline" style="color: #a94442"></span>
							</div>
                        </div>
                        <br>
                        <div class="form-group">
							<label for="state" class="col-sm-1 control-label">小说分类：</label>
							  <div class="col-sm-8 ">
                             <select id="novelType" name="novelType" class="form-control select2">
                               	<option selected="selected" value="1">热门</option>
                                <option value="2">男生</option>
                                <option value="3">女生</option>
                                <option value="4">成人</option>
                             </select>
                             </div>
                        </div>
                        <br>
                         <div class="form-group">
                            <label for="novelAuthor" class="col-sm-2 control-label">小说作者：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="novelAuthor" class="form-control" name="novelAuthor" value="${obj.novelAuthor}"
                                       placeholder="小说作者">
                            </div>
                        </div>
                        <br>

                        <div class="form-group">
                            <label for="novelName" class="col-sm-2 control-label">小说名称：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="novelName" class="form-control" name="novelName" value="${obj.novelName}"
                                       placeholder="小说名称">
                            </div>
                        </div>
                        <br>
                         <div class="form-group">
                            <label for="novelSynopsis" class="col-sm-2 control-label">小说简介：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="novelSynopsis" class="form-control" name="novelSynopsis" value="${obj.novelSynopsis}"
                                       placeholder="小说简介">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="sort" class="col-sm-2 control-label">排序：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="sort" class="form-control" name="sort" value="${obj.sort}"
                                       placeholder="排序">
                            </div>
                        </div>
                        <br>
                         <input type="hidden" name ="id" id="id" value="${obj.id}"/>
                        <div class="col-md-offset-5 col-md-9">
                            <button type="submit" class="btn btn-success">确定</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- /.row -->
<%@ include file="/content/js.jsp"%>
<script type="text/javascript">
var novelType = ${obj.novelType};
$(function(){
	//初始化下拉框默认值
	document.getElementById("novelType").value = novelType;
	//封面上传
	   $("#novelCoverFile").fileinput({
	   	uploadUrl:"<%=path%>/novel/uploadOSS",
	       browseClass: "btn btn-primary",
	       enctype: 'multipart/form-data',
	       autoReplace:true,
	       dropZoneEnabled:false,
	       browseLabel: "上传",
	       showCaption: false,
	       showRemove: false,
	       showUpload: true,
	       showZoom:false,
	       maxFileCount:1, ////表示允许同时上传的最大文件个数
	       allowedFileTypes:["image"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
	       previewSettings:{
	       	image: {width: "auto", height: "100px"},
	       },
	   });
	   $('#novelCoverFile').on('fileuploaded', function(event, data, previewId, index) {
	   	var path = data.response.initialPreviewConfig[0].extra.path;
	       $("#novelCoverUrl").val(path);
	   });
	   $('#novelCoverFile').on('filedeleted', function(event,key,jqXHR,data) {
	   	if($("#novelCoverUrl").val()==data.path)
	   		$("#novelCoverUrl").val('');
	   }); 

	   $("#novelContentFile").fileinput({
	   	uploadUrl:"<%=path%>/novel/uploadOSS",
	       browseClass: "btn btn-primary",
	       autoReplace:true,
	       dropZoneEnabled:false,
	       browseLabel: "上传",
	       showCaption: false,
	       showRemove: false,
	       showPreview:false,
	       showUpload: true,
	       showZoom:false,
	       maxFileCount:1, ////表示允许同时上传的最大文件个数
//	        allowedFileTypes:["video"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
	       maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
	       previewSettings:{
	       		type:"video",
	    		video: {width: "auto", height: "100px"},
	      },
	   });
	   $('#novelContentFile').on('fileuploaded', function(event, data, previewId, index) {
	   	var path = data.response.initialPreviewConfig[0].extra.path;
	       $("#novelContentUrl").val(path);
	       $("#novelContentUrl").triggerHandler("blur");
	   });
	   $('#novelContentFile').on('filedeleted', function(event,key,jqXHR,data) {
	   	if($("#novelContentUrl").val()==data.path)
	   		$("#novelContentUrl").val('');
	   	$("#novelContentUrl").triggerHandler("blur");
	   }); 
	});

	function saveInfo(){
		var id = $("#id").val();
		var novelCover = $("#novelCoverUrl").val();
		var novelContent = $("#novelContentUrl").val();
		var novelType = $("#novelType").val();
		var novelAuthor = $("#novelAuthor").val();
		var novelName = $("#novelName").val();
		var novelSynopsis = $("#novelSynopsis").val();
		var sort = $("#sort").val();
		$.ajax({
			type:"post",
			async: false,
			url:"<%=path%>/novel/alertNovelSave",
			data:{id:id,
				novelCover:novelCover,
				novelContent:novelContent,
				novelType:novelType,
				novelAuthor:novelAuthor,
				novelName:novelName,
				novelSynopsis:novelSynopsis,
				sort:sort},
			dataType:"json",
			success: function(data){
				if (data.missage == "success") {
                    modalMsg("修改成功", "success");
                    window.parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }else if(data.missage == "error"){
                	 modalMsg("修改失败", "error");
                }else{
                	 modalMsg("更新失败", "error");
                }
			}
		});
	}
</script>
</body>
</html>